package com.nanning.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nanning.common.utils.StringUtils;
import com.nanning.system.domain.HeavyCar;
import com.nanning.system.mapper.HeavyCarMapper;
import com.nanning.system.service.IHeavyCarService;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 在途重车预警站点情况 服务实现类
 * </p>
 *
 * @author zhurenwang
 * @since 2025-05-03
 */
@Service
public class HeavyCarServiceImpl extends ServiceImpl<HeavyCarMapper, HeavyCar> implements IHeavyCarService {

    private static final Map<String, String> map = new HashMap<>();

    static {
        map.put("融水", "1,16-1,17-1,18");
        map.put("东安", "2,16-2,17-2,18");
        map.put("黎塘", "3,16-3,17-3,18");
        map.put("六景", "4,16-4,17-4,18");
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void importData(Sheet sheet) {
        baseMapper.delete(new QueryWrapper<>());
        int rows = sheet.getPhysicalNumberOfRows();
        for (int i = 1; i < rows; i++) {
            Row row = sheet.getRow(i);
            Cell cell = row.getCell(15);
            String site = cell.getStringCellValue();
            if (StringUtils.isEmpty(site)) return;
            HeavyCar heavyCar = new HeavyCar();
            heavyCar.setArea(site);
            heavyCar.setUnloadCarNum(BigDecimal.valueOf(row.getCell(16).getNumericCellValue()));
            heavyCar.setInCarNum(BigDecimal.valueOf(row.getCell(17).getNumericCellValue()));
            heavyCar.setOutCarNum(BigDecimal.valueOf(row.getCell(18).getNumericCellValue()));
            save(heavyCar);
        }
    }
}
